﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Invoice.aspx.cs" Inherits="Delivery_Invoice" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Invoice管理</title>    
    <link href="../CSS/SubStyle.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/delivery.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../Jscript/wyyjs.js"></script>
    <script type="text/javascript" src="Jscript/popcalendar.js"></script>
    <script type="text/javascript" language="javascript">
        function boundvalid() {
            boundsource("txtDate", "^.+$", "不能为空--Not null", "cmdAdd,cmdEdit"); 
            boundsource("txtInvoicAmount", "^.+$", "不能为空--Not null", "cmdAdd,cmdEdit");
            boundsource("txtInvoiceNo", "^.+$", "不能为空--Not null", "cmdAdd,cmdEdit,cmdSure");
        }
        function txtIsNumber(txtID) {
            var a = document.getElementById(txtID).value;
            if (!(Math.abs(a) == a) || a == "") {
                alert("只能是非负数,也不能为空-Not less than zero！");
                document.getElementById(txtID).value = "0";
                document.getElementById(txtID).focus();
                return false;
            }
            return true;
        }
    </script>
    <style type="text/css">
        .style1
        {
            width: 95%;
            height: 8px;
            background-color: #AABFD2;
            border: solid 1px #B3B1B2;
        }
    </style>
</head>
<body onload="boundvalid();">
    <form id="form1" runat="server" enctype="multipart/form-data">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
        <table cellpadding="0" cellspacing="0" class="topTable">
            <tr>
                <td class="topTd">
                    <asp:Label ID="lblLocation" runat="server" Text="<%$ Resources:language, Location %>"></asp:Label><img
                        alt="当前位置" src="../Image/weizhi.gif" />>><asp:Label ID="Label1" runat="server" Text="Invoice管理"></asp:Label><asp:Label
                            ID="Label2" runat="server" Text="<%$ Resources:language, Must1 %>"></asp:Label><font
                                color="#ff0000">*</font><asp:Label ID="Label3" runat="server" Text="<%$ Resources:language, Must2 %>"></asp:Label>
                </td>
            </tr>
        </table>
         <asp:UpdatePanel ID="updHead" runat="server">
       <ContentTemplate>
                    <fieldset>
                        <legend><font style="font-size: 12px;">
                            <asp:Label ID="lblLegend1" runat="server" Text="Invoice Head"></asp:Label></font></legend>
                        <table border="0" cellpadding="0" cellspacing="0" class="InputTable">
                            <tr>
                                <td colspan="1" class="style1">
                                    <table cellpadding="0" cellspacing="0" style="width: 100%; height: 100%;"  class="InputTable">                                        
                                        <tr>
                                            <td class="td10" style="height: 10px">
                                            </td>
                                            <td class="td20" style="height: 10px">
                                            </td>
                                            <td class="td10" style="height: 10px">
                                            </td>
                                            <td class="td20" style="height: 10px">
                                            </td>
                                            <td class="td10" style="height: 10px">
                                            </td>
                                            <td style="height: 10px; text-align: left" class="td20">
                                            </td>
                                            <td style="height: 10px; text-align: left" class="td10">
                                                </td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                <span style="color: #ff0000">*</span>
                                                <asp:Label ID="Label5" runat="server" Text="发票号:"></asp:Label></td>
                                            <td class="td20">
                                                <asp:TextBox ID="txtInvoiceNo" CssClass="txtStyle" runat="server" 
                                                    MaxLength="20"></asp:TextBox>
                                            </td>
                                            <td class="td10">
                                                <span style="color: #ff0000">*</span><asp:Label ID="Label6" runat="server" Text="发票金额:"></asp:Label></td>
                                            <td class="td20">
                                                <input type="text" id="txtInvoicAmount" runat="server" class="txtStyle" onblur="InitiLeftAmount(txtIsNumber(this.id))" 
                                                    maxlength="50" value="0" /></td>
                                                    <script language="javascript" type="text/javascript">
                                                        function InitiLeftAmount() {
                                                            document.getElementById("txtLeftAmount").value = document.getElementById("txtInvoicAmount").value;
                                                        }
                                                    </script>
                                              <td class="td10">
                                                <asp:Label ID="Label9" runat="server" Text="发票日期:"></asp:Label>
                                                </td> 
                                                <td class="td20">
                                                <input id="txtDate" runat="server" class="txtStyle" name="date2"
                                                 onclick="popUpCalendar(this,document.forms[0].txtDate,'yyyy-mm-dd')"
                                                        style="width: 100%; cursor: hand" type="text" /></td>
                                                <td style="text-align:left;" class="td10">
                                                    </td>
                                        </tr>
                                          <tr>
                                            <td class="td10">
                                                &nbsp;<asp:Label ID="Label7" runat="server" Text="快递单号:"></asp:Label></td>
                                            <td class="td20">
                                                <asp:TextBox ID="txtExpressDeliveryNo" CssClass="txtStyle" runat="server" 
                                                    MaxLength="20"></asp:TextBox>
                                            </td>
                                            <td class="td10">
                                                <asp:Label ID="Label13" runat="server" Text="寄发日期:"></asp:Label></td>
                                            <td class="td20">
                                                <input id="txtDespatchDate" runat="server" class="txtStyle" name="date3"
                                                 onclick="popUpCalendar(this,document.forms[0].txtDespatchDate,'yyyy-mm-dd')"
                                                        style="width: 100%; cursor: hand" type="text" />
                                              </td>
                                                    <script language="javascript" type="text/javascript">
                                                        function InitiLeftAmount() {
                                                            document.getElementById("txtLeftAmount").value = document.getElementById("txtInvoicAmount").value;
                                                        }
                                                    </script>
                                              <td class="td10">
                                                <asp:Label ID="Label19" runat="server" Text="签收日期:"></asp:Label>
                                                </td> 
                                                <td class="td20">
                                                <input id="txtSignInDate" runat="server" class="txtStyle" name="date2"
                                                 onclick="popUpCalendar(this,document.forms[0].txtSignInDate,'yyyy-mm-dd')"
                                                        style="width: 100%; cursor: hand" type="text" /></td>
                                                <td style="text-align:left;" class="td10">
                                                    </td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                <asp:Label ID="Label8" runat="server" Text="<%$ Resources:hwlan, desc %>"></asp:Label>
                                            </td>
                                            <td class="td20" colspan="3" style="height: 22px">
                                                <asp:TextBox ID="TxtDesc" runat="server" CssClass="txtStyle" MaxLength="100"></asp:TextBox>
                                            </td>
                                            <td class="td10">
                                                <asp:Label ID="Label17" runat="server" Text="可用金额:"></asp:Label>
                                            </td>
                                            <td class="td20">
                                                <input type="text" id="txtLeftAmount" runat="server" class="txtStyle" onblur="txtIsNumber(this.id)" 
                                                    maxlength="50" disabled="disabled" value="0" style="background-color: #CCCCCC" />
                                            </td>
                                            <td class="td10">
                                                &nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                <asp:Label ID="Label20" runat="server" Text="上传附件:"></asp:Label>
                                            </td>
                                            <td class="td20" colspan="3" style="height: 22px">
                                                <asp:FileUpload ID="FileUpload1" runat="server" CssClass="txtStyle" />
                                            </td>
                                            <td align="left">
                                                <asp:Button ID="cmdSure" runat="server" CssClass="cmdStyle" 
                                                    onclick="cmdSure_Click" Text="上传" />
                                            </td>
                                            <td class="td20">
                                                &nbsp;</td>
                                            <td class="td10">
                                                &nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                &nbsp;</td>
                                            <td class="td20" colspan="3">
                                                    <div id="Div1" style="overflow-y: auto; overflow-x: auto; text-align:center;">
                            <asp:GridView ID="GrvFiles" runat="server"
                                CssClass="gvStyle"
                                AllowPaging="True" GridLines="None" PageSize="20" 
                                OnRowDeleting="GrvFiles_RowDeleting" AutoGenerateColumns="False" EmptyDataText="No Files!" 
                                                            DataKeyNames="M_InvoiceFilesID,filePath" onrowdatabound="GrvFiles_RowDataBound">
                                <HeaderStyle CssClass="gvHeader" />
                                <RowStyle CssClass="gvRow" />
                                <AlternatingRowStyle CssClass="gvAllRow" />
                                <Columns>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            NO.</HeaderTemplate>
                                        <ItemTemplate>
                                            <%#GrvFiles.PageIndex * GrvFiles.PageSize + GrvFiles.Rows.Count + 1%>
                                        </ItemTemplate>
                                        <ItemStyle CssClass="gvItem" />
                                    </asp:TemplateField>
                                    <asp:HyperLinkField DataNavigateUrlFields="filePath" HeaderText="File Name"
                                DataNavigateUrlFormatString="../FilesDownLoad.aspx?filePosition=InvoiceUploadFiles/{0}"
                                 DataTextField="InvoiceFileName">
                                <ItemStyle CssClass="gvItem" Height="25px" />
                                <ControlStyle CssClass="lianjie" />
                            </asp:HyperLinkField>
                                    <asp:CommandField ShowDeleteButton="True" DeleteText="&lt;img border=0 alt=&quot;Delete&quot; src=../Image/del.gif&gt;"
                                        HeaderText="<%$ Resources:language, Delete %>">
                                        <ItemStyle CssClass="gvItem" />
                                    </asp:CommandField>
                                </Columns>
                            </asp:GridView>                
             </div>   
                                              </td>
                                            <td align="left">
                                                &nbsp;</td>
                                            <td class="td20">
                                                &nbsp;</td>
                                            <td class="td10">
                                                &nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                </td>
                                            <td class="td20" colspan="3" style="height: 22px">
                                                &nbsp;</td>
                                            <td class="td10">
                                            </td>
                                            <td class="td20" >
                                                </td>
                                            <td class="td10" >
                                                </td>
                                        </tr>
                                        </table>
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset id="lineFieldset" runat="server">
                        <legend><font style="font-size: 12px;">
                            <asp:Label ID="Label4" runat="server" Text="Invoice Line"></asp:Label></font></legend>
                        <table border="0" cellpadding="0" cellspacing="0" class="InputTable">
                            <tr>
                                <td colspan="1" class="style1">
                                    <table cellpadding="0" cellspacing="0" style="width: 100%; height: 100%;"  class="InputTable">                                        
                                        <tr>
                                            <td class="td10" style="height: 10px">
                                            </td>
                                            <td class="td20" style="height: 10px">
                                            </td>
                                            <td class="td10" style="height: 10px">
                                            </td>
                                            <td class="td20" style="height: 10px">
                                            </td>
                                            <td class="td10" style="height: 10px">
                                            </td>
                                            <td style="height: 10px; text-align: left" class="td20">
                                            </td>
                                            <td style="height: 10px; text-align: left" class="td10">
                                                </td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                <asp:Label ID="Label14" runat="server" Text="类型:"></asp:Label></td>
                                            <td class="td20">
                                                <asp:DropDownList ID="ddlType" runat="server" AutoPostBack="True" 
                                                    onselectedindexchanged="ddlType_SelectedIndexChanged" Width="102%">
                                                    <asp:ListItem Selected="True" Value="0">按合同</asp:ListItem>
                                                    <asp:ListItem Value="1">按SO# Trading</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                            <td class="td10">
                                                <asp:Label ID="Label18" runat="server" Text="合同可用金额:"></asp:Label>
                                            </td>
                                            <td class="td20">
                                                <input type="text" id="txtContractLeftAmount" runat="server" class="txtStyle" onblur="txtIsNumber(this.id)" 
                                                    maxlength="50" disabled="disabled" value="0" style="background-color: #CCCCCC" />
                                            </td>
                                              <td class="td10" align="right">
                                                  <asp:Label ID="Label10" runat="server" Text="金额:"></asp:Label>
                                            </td> 
                                                <td style="text-align:left;" class="td20">
                                                    <input type="text" id="txtAmount" runat="server" class="txtStyle" onblur="AmountCheck(txtIsNumber(this.id))" 
                                                    maxlength="50" value="0" />
                                                    <script language="javascript" type="text/javascript">
                                                        function AmountCheck(flag) {
                                                            if (flag) {
                                                                var a = document.getElementById("txtLeftAmount").value;
                                                                var b = document.getElementById("txtAmount").value;
                                                                var c = document.getElementById("txtContractLeftAmount").value;
                                                                if (c < 0) { document.getElementById("txtContractLeftAmount").value = 0; }
                                                                if (window.Math.abs(b) > window.Math.abs(a)
                                                                || window.Math.abs(b) > window.Math.abs(c)) {
                                                                    window.alert("金额过大！");
                                                                    document.getElementById("txtAmount").value = a > c ? c : a;
                                                                }
                                                            }
                                                        }
                                                    </script>
                                            </td>
                                                <td style="text-align:left;" class="td10">
                                                    </td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                <asp:Label ID="Label15" runat="server" Text="合同号:"></asp:Label>
                                                </td>
                                            <td class="td20" colspan="3" style="height: 22px">
                                                <asp:DropDownList ID="ddlContractNo" runat="server" AutoPostBack="True" 
                                                    onselectedindexchanged="ddlContractNo_SelectedIndexChanged" Width="101%" 
                                                    >
                                                </asp:DropDownList>
                                                </td>
                                            <td class="td10">
                                                <asp:Label ID="Label16" runat="server" Text="SO#"></asp:Label>
                                            </td>
                                            <td class="td20" >
                                                <asp:DropDownList ID="ddlSoNo" runat="server" Enabled="False" Width="102%" 
                                                    onselectedindexchanged="ddlSoNo_SelectedIndexChanged">
                                                </asp:DropDownList>
                                                </td>
                                            <td class="td10" >
                                                </td>
                                        </tr>
                                        <tr>
                                            <td class="td10">
                                                </td>
                                            <td class="td20" colspan="3" style="height: 22px">
                                                </td>
                                            <td class="td10">
                                                </td>
                                            <td class="td20">
                                                </td>
                                            <td class="td10">
                                                </td>
                                        </tr>
                                        </table>
                                </td>
                            </tr>
                        </table>                            
                        <div style="text-align:center; width:100%"> 
                        <asp:Button ID="cmdAdd" runat="server" Text="<%$ Resources:hwlan, insert %>"
                                        CssClass="cmdStyle" OnClick="cmdAdd_Click" />
                                    &nbsp;<asp:Button ID="cmdEdit" 
                                        runat="server" Text="<%$ Resources:hwlan, edit %>"
                                        CssClass="cmdStyle" Enabled="False" onclick="cmdEdit_Click1" />
                            <asp:HiddenField ID="hiddEdit" runat="server" />
                       </div>
                    </fieldset> 
        <fieldset style="width:99%; text-align:center;">
            <legend><span style="font-size: 12px;">
                <asp:Label ID="lblLegend2" runat="server" Text="Invoice Contract"></asp:Label></span></legend>
            <div id="detailDiv" style="overflow-y: auto; overflow-x: scroll;">
                            <asp:GridView ID="Grv" runat="server"
                                CssClass="gvStyle" Width="100%"
                                AllowPaging="True" GridLines="None" PageSize="300" 
                                OnRowDeleting="GrvColumns_RowDeleting" AutoGenerateColumns="False" 
                                DataKeyNames="M_InvoiceContractID" 
                                onselectedindexchanged="Grv_SelectedIndexChanged">
                                <HeaderStyle CssClass="gvHeader" />
                                <RowStyle CssClass="gvRow" />
                                <AlternatingRowStyle CssClass="gvAllRow" />
                                <Columns>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            NO.</HeaderTemplate>
                                        <ItemTemplate>
                                            <%#Grv.PageIndex * Grv.PageSize + Grv.Rows.Count + 1%>
                                        </ItemTemplate>
                                        <ItemStyle CssClass="gvItem" />
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="ContractNoMain" HeaderText="ContractNo.(ITT)">
                                        <ItemStyle CssClass="gvItem" HorizontalAlign="left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="SONo" HeaderText="SO#">
                                        <ItemStyle CssClass="gvItem" HorizontalAlign="left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="InvoiceNo" HeaderText="InvoiceNo">
                                        <ItemStyle CssClass="gvItem" HorizontalAlign="left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="InvoiceContractAmount" HeaderText="Invoice Contract Amount">
                                        <ItemStyle CssClass="gvItem" HorizontalAlign="left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="InvoiceType" HeaderText="类型">                                        
                                        <ItemStyle CssClass="gvItem" />
                                    </asp:BoundField>                                    
                            <asp:CommandField HeaderText="<%$ Resources:language, Edit %>" ShowSelectButton="true"
                                SelectText="&lt;img border=0 alt=&quot;Edit&quot; src=../Image/edit.gif&gt;">
                                <ItemStyle CssClass="gvItem" />
                            </asp:CommandField>
                                    <asp:CommandField ShowDeleteButton="True" DeleteText="&lt;img border=0 alt=&quot;Delete&quot; src=../Image/del.gif&gt;"
                                        HeaderText="<%$ Resources:language, Delete %>">
                                        <ItemStyle CssClass="gvItem" />
                                    </asp:CommandField>
                                </Columns>
                                <PagerTemplate>
                                    <table style="width: 100%;">
                                        <tr>
                                            <td align="left">
                                                <asp:Label ID="lblTotal1" runat="server" Text="<%$ Resources:UserSqlPage, Total1 %>"></asp:Label><asp:Label
                                                    ID="lblCount" runat="server"></asp:Label><asp:Label ID="Total2" runat="server" Text="<%$ Resources:UserSqlPage, Total2 %>"></asp:Label>,<asp:Label
                                                        ID="Label5" runat="server" Text="<%$ Resources:UserSqlPage, CurrentPage1 %>"></asp:Label><asp:Label
                                                            ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' /><asp:Label
                                                                ID="Label11" runat="server" Text="<%$ Resources:UserSqlPage, CurrentPage2 %>"></asp:Label>,<asp:Label
                                                                    ID="Label3" runat="server" Text="<%$ Resources:UserSqlPage, TotalPage1 %>"></asp:Label><asp:Label
                                                                        ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount  %>' /><asp:Label
                                                                            ID="Label12" runat="server" Text="<%$ Resources:UserSqlPage, TotalPage2 %>"></asp:Label>
                                                <% //首页/上一页 %>
                                                <% if (this.Grv.PageIndex <= 0)
                                                   { %>
                                                <asp:LinkButton ID="LinkButton1" runat="server" Enabled="false" Text="<%$ Resources:UserSqlPage, FirstPage %>" />&nbsp;
                                                <asp:LinkButton ID="LinkButton2" runat="server" Enabled="false" Text="<%$ Resources:UserSqlPage, PreviousPage %>" />&nbsp;
                                                <% }
                                                   else
                                                   { %>
                                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandArgument="First"
                                                    CommandName="Page" Text="<%$ Resources:UserSqlPage, FirstPage %>" />&nbsp;
                                                <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandArgument="Prev"
                                                    CommandName="Page" Text="<%$ Resources:UserSqlPage, PreviousPage %>" />&nbsp;
                                                <% } %>
                                                <% //下一页/尾页 %>
                                                <% if (this.Grv.PageIndex >= Grv.PageCount - 1)
                                                   { %>
                                                <asp:LinkButton ID="LinkButton5" runat="server" Enabled="false" Text="<%$ Resources:UserSqlPage, NextPage %>" />&nbsp;
                                                <asp:LinkButton ID="LinkButton6" runat="server" Enabled="false" Text="<%$ Resources:UserSqlPage, LastPage %>" />
                                                <% }
                                                   else
                                                   { %>
                                                <asp:LinkButton ID="LinkButton7" runat="server" CausesValidation="False" CommandArgument="Next"
                                                    CommandName="Page" Text="<%$ Resources:UserSqlPage, NextPage %>" />&nbsp;
                                                <asp:LinkButton ID="LinkButton8" runat="server" CausesValidation="False" CommandArgument="Last"
                                                    CommandName="Page" Text="<%$ Resources:UserSqlPage, LastPage %>" />
                                                <% } %>
                                                <asp:TextBox ID="txtNewPageIndex" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>"
                                                    Width="20px"></asp:TextBox>
                                                <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
                                                    CommandName="NewPage" Text="<%$ Resources:UserSqlPage, PageGo %>"></asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                </PagerTemplate>
                            </asp:GridView>                
             </div>   
        </fieldset>  
        <div style="text-align:center;">
            <asp:Button ID="cmdDelete" CssClass="cmdStyle" runat="server" Text="删除" 
                onclick="cmdDelete_Click" />
            <asp:Button ID="cmdBack" CssClass="cmdStyle" runat="server" Text="Back" OnClientClick="history.back();"
               />
        </div>
        </ContentTemplate>        
     <Triggers>
     <asp:PostBackTrigger ControlID="cmdSure" />     
     </Triggers></asp:UpdatePanel>  
    </form>
</body>
</html>